package edu.mju.scenic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import edu.mju.scenic.entity.Attractions;
import edu.mju.scenic.entity.Celebrity;
import edu.mju.scenic.mapper.AttractionsMapper;
import edu.mju.scenic.service.AttractionsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CBL
 * @since 2020-12-28
 */
@Service
public class AttractionsServiceImpl extends ServiceImpl<AttractionsMapper, Attractions> implements AttractionsService {


    @Override
    public boolean deleteByAttractionsId(Integer id) {

        return baseMapper.deleteByAttractionsId(id);
    }

    @Override
    public boolean deleteBySpotId(Integer id) {
        return baseMapper.deleteBySpotId(id);
    }

    @Override
    public List<Attractions> listBySpotId(Integer spotId) {
        QueryWrapper<Attractions> wrapper = new QueryWrapper<>();
        wrapper.eq("spot_id",spotId);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public Map<String, Object> getCelebrity(IPage<Attractions> attractionsIPage) {
        QueryWrapper<Attractions> celebrityQueryWrapper = new QueryWrapper<>();
        celebrityQueryWrapper.eq("status",1);
        baseMapper.selectPage(attractionsIPage,celebrityQueryWrapper);

        long total = attractionsIPage.getTotal();
        List<Attractions> records = attractionsIPage.getRecords();

        Map<String,Object> map = new HashMap<>();
        map.put("total",total);
        map.put("attractionsList",records);

        return map;
    }
}
